import 'package:flutter/material.dart';
import 'package:flutter_ebook/pages/home/home_page.dart';
import 'package:flutter_ebook/pages/root/root_page.dart';
import 'package:flutter_ebook/theme/dark_theme.dart';
import 'package:flutter_ebook/theme/theme_provider.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

Size get designSize {
  //
  final firstView = WidgetsBinding.instance.platformDispatcher.views.first;
  // 逻辑短边
  final logicalShortestSize =
      firstView.physicalSize.shortestSide / firstView.devicePixelRatio;
  // 逻辑长边
  final logicalLongestSize =
      firstView.physicalSize.longestSide / firstView.devicePixelRatio;
  // 缩放比例
  const scaleFactor = 0.95;
  return Size(
      logicalLongestSize * scaleFactor, logicalShortestSize * scaleFactor);
}

class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      // 屏幕适配设计尺寸
      // designSize: const Size(375, 812),
      designSize: designSize,
      builder: (context, child) => MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Flutter Demo',
        theme: Provider.of<ThemeProvider>(context, listen: true).themeData,
        darkTheme: darkMode,
        home: const RootPage(),
      ),
    );
  }
}
